package com.bai.process.controller;


import com.bai.common.Result;
import com.bai.model.process.Process;
import com.bai.model.vo.process.ApprovalVo;
import com.bai.model.vo.process.ProcessQueryVo;
import com.bai.model.vo.process.ProcessVo;
import com.bai.process.service.OaProcessService;
import com.bai.serviceOA.service.SysUserService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 审批类型 前端控制器
 * </p>
 *
 * @author bai
 * @since 2023-06-01
 */
@Api("管理审批流")
@RestController
@RequestMapping("/admin/process")
public class OaProcessController {

    @Autowired
    private OaProcessService processService;
    @Autowired
    private SysUserService sysUserService;

    /**
     * 列表
     */
    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page,
                        @PathVariable Long limit,
                        ProcessQueryVo processQueryVo) {
        Page<ProcessVo> processPage = new Page<>(page, limit);
        IPage<ProcessVo> pageModel = processService.selectPage(processPage, processQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 待处理列表
     */
    @ApiOperation(value = "待处理")
    @GetMapping("/findPending/{page}/{limit}")
    public Result findPending(@PathVariable Long page,
                              @PathVariable Long limit) {
        Page<Process> pageParam = new Page<>(page, limit);
        IPage<ProcessVo> pageModel = processService.findPending(pageParam);
        return Result.ok(pageModel);
    }

    /**
     * 查看审批详情
     *
     * @param id
     * @return
     */
    @GetMapping("/show/{id}")
    public Result show(@PathVariable Long id) {
        Map<String, Object> map = processService.show(id);
        return Result.ok(map);
    }

    /**
     * 审批
     *
     * @param approvalVo
     * @return
     */
    @ApiOperation(value = "审批")
    @PostMapping("approve")
    public Result approve(@RequestBody ApprovalVo approvalVo) {
        processService.approve(approvalVo);
        return Result.ok();
    }

    /**
     * 已处理
     */
    @ApiOperation(value = "已处理")
    @GetMapping("findProcessed/{page}/{limit}")
    public Result findProcessedPage(@PathVariable Long page,
                                    @PathVariable Long limit) {
        Page<Process> pageParam = new Page<>(page, limit);
        IPage<ProcessVo> pageModel = processService.findProcessed(pageParam);
        return Result.ok(pageModel);
    }

    /**
     * 已发起
     */
    @ApiOperation(value = "已发起")
    @GetMapping("/findStarted/{page}/{limit}")
    public Result findStart(@PathVariable Long page,
                            @PathVariable Long limit) {
        Page<ProcessVo> pageParam = new Page<>(page, limit);
        IPage<ProcessVo> pageModel = processService.findStarted(pageParam);
        return Result.ok();
    }

    @ApiOperation(value = "获取当前用户信息")
    @GetMapping("getCurrentUser")
    public Result getCurrentUser() {
        Map<String, Object> map = sysUserService.getCurrentUser();
        return Result.ok(map);
    }
}

